package com.fh.alipay.utils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.fh.alipay.dto.BizContent;
import com.fh.alipay.dto.LqiDto;

public class InputParamSignUtil {
//    public static void main(String[] args) {
//        String sysSecret = "00000000000000000000000000000000";
//            String sign = sign(sysSecret,new LqiDto());
//        System.out.println(sign);
//    }

    public static String sign(String secret, LqiDto lqiDto) {
//        lqiDto.setMethod("order.direct.add");
//        lqiDto.setTimestamp(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:dd")));
//        BizContent bizContent = new BizContent();
//        bizContent.setAccount_type("1");
//        lqiDto.setBiz_content(bizContent);
        Map<String, String> map = new HashMap<String, String>();
        map.put("app_key", "683948911");
        map.put("method", lqiDto.getMethod());
        map.put("timestamp", lqiDto.getTimestamp());
        map.put("version", "2.0");
        map.put("format", "json");
        map.put("charset", "utf-8");
        map.put("sign_type", "md5");
        map.put("app_auth_token", "");
        map.put("biz_content", JSONObject.toJSONString(lqiDto.getBiz_content()));
        net.sf.json.JSONObject resultJson = net.sf.json.JSONObject.fromObject(map);
        System.out.println(resultJson);
        char[] s = JSONObject.toJSONString(resultJson, SerializerFeature.WriteMapNullValue).toCharArray();
        Arrays.sort(s);
        String outputSignOriginalStr = new String(s) + secret;
        return MD5Utils.MD5(outputSignOriginalStr);
    }
}